<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
</head>

<body>
    <pre>

    ★★★★★
    扩展运算符可以将数组或者对象转为用逗号分隔的参数序列。

    展开运算符
  </pre
    >

    <div>
      <span>1</span>
      <span>2</span>
      <span>3</span>
      <span>4</span>
    </div>

    <script>
      // 1.
      // let a = [1, 2, 3];
      // let b = [4, 5, 6];
      // console.log(...a); // 1, 2, 3
      // let c = [...a, ...b];
      // console.log(c); //  [1, 2, 3, 4, 5, 6]

      // 2. 将伪数组转换为真实的数据
      // let spans = document.querySelectorAll("span");
      // console.log(spans); // NodeList(4) [span, span, span, span]
      // console.log([...spans]); // [span, span, span, span]

      // 3. 利用拓展运算符合并数组，
      const a = [1, 2, 3];
      const b = ["a", "b", "c"];
      const c = [...a, ...b];
      console.log(c); // [1, 2, 3, "a", "b", "c"]
      a.push(...b);
      console.log(a); // [1, 2, 3, "a", "b", "c"]

      // ---------------------------------------
      // 小结：
      // 合并数组
      // // 方法一
      // let ary1 = [1, 2, 3]; let ary2 = [3, 4, 5];
      // let ary3 = [...ary1, ...ary2];
      // // 方法二
      // ary1.push(...ary2);
      // 将类数组或可遍历对象转换为真正的数组
    </script>
  </body>
</html>